<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="UTF-8">
  <meta 
    name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
  <meta 
    http-equiv="X-UA-Compatible" 
    content="ie=edge">
  <meta 
    name="theme-color" 
    content="#fff" 
    id="theme-color">
  <meta 
    name="description" 
    content="程序员的快乐小网站">
  <link 
    rel="icon" 
    href="https://demo.theme-kaze.top/img/Kaze.png">
  <title>PHP数据类型</title>
  
    
      <meta 
        property="og:title" 
        content="PHP数据类型">
    
    
      <meta 
        property="og:url" 
        content="http://www.baikaihua.gitee.io/2021/09/19/PHP%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/index.html">
    
    
      <meta 
        property="og:img" 
        content="https://gitee.com/baikaihua/tochang/raw/master/src=http___b-ssl.duitang.com_uploads_item_201607_07_20160707163006_EnLeG.jpeg&amp;refer=http___b-ssl.duitang.jpg">
    
    
      <meta 
        property="og:img" 
        content="&lt;p&gt;PHP数据类型&lt;/p&gt;
&lt;p&gt;作者：徐威&lt;/p&gt;">
    
    
      <meta 
        property="og:type" 
        content="article">
      <meta 
        property="og:article:published_time" 
        content="2021-09-19">
      <meta 
        property="og:article:modified_time" 
        content="2021-09-19">
      <meta 
        property="og:article:author" 
        content="白开画 and 徐威">
      
        
          <meta 
            property="og:article:tag" 
            content="徐威">
        
          <meta 
            property="og:article:tag" 
            content="PHP">
        
          <meta 
            property="og:article:tag" 
            content="web脚本">
        
      
    
  
  <script>
    function loadScript(url, cb) {
      var script = document.createElement('script');
      script.src = url;
      if (cb) script.onload = cb;
      script.async = true;
      document.body.appendChild(script);
    }
    function loadCSS(href, data, attr) {
      var sheet = document.createElement('link');
      sheet.ref = 'stylesheet';
      sheet.href = href;
      sheet.dataset[data] = attr;
      document.head.appendChild(sheet);
    }
    function changeCSS(cssFile, data, attr) {
      var oldlink = document.querySelector(data);
      var newlink = document.createElement("link");
      newlink.setAttribute("rel", "stylesheet");
      newlink.setAttribute("href", cssFile);
      newlink.dataset.prism = attr;
      document.head.replaceChild(newlink, oldlink);
    }
  </script>
  
    
  
  <script>
    // control reverse button
    var reverseDarkList = {
      dark: 'light',
      light: 'dark'
    };
    var themeColor = {
      dark: '#1c1c1e',
      light: '#fff'
    }
    // get the data of css prefers-color-scheme
    var getCssMediaQuery = function() {
      return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
    };
    // reverse current darkmode setting function
    var reverseDarkModeSetting = function() {
      var setting = localStorage.getItem('user-color-scheme');
      if(reverseDarkList[setting]) {
        setting = reverseDarkList[setting];
      } else if(setting === null) {
        setting = reverseDarkList[getCssMediaQuery()];
      } else {
        return;
      }
      localStorage.setItem('user-color-scheme', setting);
      return setting;
    };
    // apply current darkmode setting
  </script>
  
    <script>
      var setDarkmode = function(mode) {
      var setting = mode || localStorage.getItem('user-color-scheme');
      if(setting === getCssMediaQuery()) {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[setting];
        document.getElementById('theme-color').dataset.mode = setting;
      } else if(reverseDarkList[setting]) {
        document.documentElement.setAttribute('data-user-color-scheme', setting);
        document.getElementById('theme-color').content = themeColor[setting];
        document.getElementById('theme-color').dataset.mode = setting;
      } else {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[getCssMediaQuery()];
        document.getElementById('theme-color').dataset.mode = getCssMediaQuery();
      }
    };
    setDarkmode();
    </script>
  
  
  <link rel="preload" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css" as="style" >
  <link rel="preload" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css" as="style" >
  
  
    <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.js" as="script">
    <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.css" as="style" >
  
  
    <link rel="preload" href="/js/lib/lozad.min.js" as="script">
  
  
  
  
    
    <link rel="prefetch" href="//cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" as="script">
  
  
    
    <link rel="prefetch" href="//unpkg.com/valine/dist/Valine.min.js" as="script">
  
  
  
  <link rel="stylesheet" href="/css/main.css">
  
  <link rel="stylesheet" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css">
  
  <link rel="stylesheet" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css">
  
    <link rel="stylesheet" href="/js/lib/lightbox/baguetteBox.min.css">
  
<meta name="generator" content="Hexo 5.4.0"></head>

  <body>
    <div class="wrapper">
       
      <nav class="navbar">
  <div class="navbar-logo">
    <span class="navbar-logo-main">
      
        <img 
          class="navbar-logo-img" 
          src="https://demo.theme-kaze.top/img/Kaze.png" 
          alt="blog logo">
      
      <span class="navbar-logo-dsc">程序小站</span>
    </span>
  </div>
  <div class="navbar-menu">
    
      <a 
        href="/" 
        class="navbar-menu-item">
        
          首页
        
      </a>
    
      <a 
        href="/archives" 
        class="navbar-menu-item">
        
          归档
        
      </a>
    
      <a 
        href="/tags" 
        class="navbar-menu-item">
        
          标签
        
      </a>
    
      <a 
        href="/categories" 
        class="navbar-menu-item">
        
          分类
        
      </a>
    
      <a 
        href="/about" 
        class="navbar-menu-item">
        
          关于
        
      </a>
    
    <a 
      class="navbar-menu-item darknavbar" 
      id="dark">
      <i class="iconfont icon-weather"></i>
    </a>
    <a 
      class="navbar-menu-item searchnavbar" 
      id="search">
      <i 
        class="iconfont icon-search" 
        style="font-size: 1.2rem; font-weight: 400;">
      </i>
    </a>
  </div>
</nav> 
      
      <div 
        id="local-search" 
        style="display: none">
        <input
          class="navbar-menu-item"
          id="search-input"
          placeholder="请输入搜索内容..." />
        <div id="search-content"></div>
      </div>
      
      <div class="section-wrap">
        <div class="container">
          <div class="columns">
            <main class="main-column">
<article class="card card-content">
  <header>
    <h1 class="post-title">
      PHP数据类型
    </h1>
  </header>
  <div class="post-meta post-show-meta">
    <time datetime="2021-09-19T12:05:49.090Z">
      <i 
        class="iconfont icon-calendar" 
        style="margin-right: 2px;">
      </i>
      <span>2021-09-19</span>
    </time>
    
      <span class="dot"></span>
      
        <a 
          href="/categories/PHP/" 
          class="post-meta-link">
          PHP
        </a>
      
    
    
      <span class="dot"></span>
      <span>1.9k 字</span>
    
  </div>
  
    <div 
      class="post-meta post-show-meta" 
      style="margin-top: -10px;">
      <div style="display: flex; align-items: center;">
        <i 
          class="iconfont icon-biaoqian" 
          style="margin-right: 2px; font-size: 1.15rem;">
        </i>
        
          
          <a 
            href="/tags/%E5%BE%90%E5%A8%81/" 
            class="post-meta-link">
            徐威
          </a>
        
          
            <span class="dot"></span>
          
          <a 
            href="/tags/PHP/" 
            class="post-meta-link">
            PHP
          </a>
        
          
            <span class="dot"></span>
          
          <a 
            href="/tags/web%E8%84%9A%E6%9C%AC/" 
            class="post-meta-link">
            web脚本
          </a>
        
      </div>
    </div>
  
  </header>
  <div 
    id="section" 
    class="post-content">
    <p>PHP数据类型</p>
<p>作者：徐威</p>
<span id="more"></span>
<h2 id="php数据类型"><a class="markdownIt-Anchor" href="#php数据类型"></a> PHP数据类型</h2>
<p>PHP是一种类型比较弱的语言，就是说变量可以包含任意给定的数据类型，该类型取决于使用变量的上下问环境。在PHP中，可以直接为变量赋值，而不需要对其数据类型声明，如：</p>
<pre class="highlight"><span class="line"><span class="variable">$sy</span> = <span class="string">&quot;hullo world&quot;</span>;		<span class="comment">//表示$sy为字符串型</span></span><br><span class="line"><span class="variable">$jl</span> = <span class="number">50</span>;				   <span class="comment">//表示$jl为整型</span></span><br></pre>
<p>PHP中变量数据类型的定义是通过变量赋值（初始化），由系统自动设定。PHP支持8种原始类型，其中4种标量类型，2种复合型和2种特殊类型。</p>
<p>标量数据类型包括：boolean（布尔型）、string（字符型）、integer（整型）和 float（浮点型，也成为double）；复合数据类型包括：array（数组）和 object（对象）；特殊数据类型包括：resource（资源）和 NULL。只这么看是看不出什么门道，下面我们会一一介绍。</p>
<h3 id="标量数据类型"><a class="markdownIt-Anchor" href="#标量数据类型"></a> 标量数据类型</h3>
<p><strong>1.布尔型（boolean）</strong></p>
<p>​	在所有PHP变量中，布尔型是最简单的变量。布尔型只有 ‘true’ 和 ‘false’ 两个值，只要把 ‘true’ 和 ‘false’ 赋给变量该变量就是布尔型。 ‘true’ 和 ‘false’ 在PHP中也是关键字。</p>
<p>标准赋值⬇：</p>
<pre class="highlight"><span class="line"><span class="variable">$sy_1</span>=<span class="literal">true</span>;</span><br></pre>
<p>注意：美元符号<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi mathvariant="normal">是</mi><mi mathvariant="normal">变</mi><mi mathvariant="normal">量</mi><mi mathvariant="normal">的</mi><mi mathvariant="normal">标</mi><mi mathvariant="normal">识</mi><mi mathvariant="normal">符</mi><mi mathvariant="normal">，</mi><mi mathvariant="normal">所</mi><mi mathvariant="normal">有</mi><mi mathvariant="normal">变</mi><mi mathvariant="normal">量</mi><mi mathvariant="normal">都</mi><mi mathvariant="normal">要</mi><mi mathvariant="normal">以</mi></mrow><annotation encoding="application/x-tex">是变量的标识符，所有变量都要以</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0em;vertical-align:0em;"></span><span class="mord cjk_fallback">是</span><span class="mord cjk_fallback">变</span><span class="mord cjk_fallback">量</span><span class="mord cjk_fallback">的</span><span class="mord cjk_fallback">标</span><span class="mord cjk_fallback">识</span><span class="mord cjk_fallback">符</span><span class="mord cjk_fallback">，</span><span class="mord cjk_fallback">所</span><span class="mord cjk_fallback">有</span><span class="mord cjk_fallback">变</span><span class="mord cjk_fallback">量</span><span class="mord cjk_fallback">都</span><span class="mord cjk_fallback">要</span><span class="mord cjk_fallback">以</span></span></span></span>符号开头，无论是生命还是调用变量，都要使用$符号。</p>
<p>​	 ‘true’ 和 ‘false’ 实际上代表数字1和0，true在输出时显示为1，false在输出时显示为0。有很多情况把整型值0、浮点型值0.0、空白字符和字符串&quot;0&quot;、空值NULL认为是false。把非0认为是true。因此布尔型变量是应用在条件控制和循环中的条件表达。</p>
<p>举个栗子：</p>
<pre class="highlight"><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">	<span class="variable">$sy_1</span>=<span class="literal">true</span>;</span><br><span class="line">	<span class="keyword">if</span>(<span class="variable">$sy_1</span>==<span class="literal">true</span>)</span><br><span class="line">        <span class="keyword">echo</span><span class="string">&#x27;变量为真！&#x27;</span>;</span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">        <span class="keyword">echo</span><span class="string">&#x27;变量为假！&#x27;</span>;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre>
<p>运行结果：</p>
<p><img src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210909224106.png" alt="" / srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210909224106.png" class="lozad post-image"></p>
<p><strong>2.字符串型（string）</strong></p>
<p>字符串有一系列字符组成，其中每个字符等同于一个字节。字符串在每种编程语言中都广泛应用。在PHP中，定义字符串有三种方式。</p>
<p>1）单引号形式</p>
<p>​	定义一个字符串最简单的方法是使用单引号把它括起来，上例子：</p>
<pre class="highlight"><span class="line"><span class="variable">$sy_2</span>=<span class="string">&#x27;hello world&#x27;</span>;</span><br></pre>
<p>注意哈：在单引号定义字符串类型的变量时，PHP不会讲其按照变量进行处理，而是将其看做字符串。不支持多种转义字符。</p>
<p>2）双引号形式</p>
<p>​	双引号字符串的赋值方法，上例子：</p>
<pre class="highlight"><span class="line"><span class="variable">$sy_3</span>=<span class="string">&quot;我是双引号字符串&quot;</span>;</span><br></pre>
<p>注意哈：用双引号形式支持多种转义字符，例：&quot;\n&quot;表示换行,&quot;\r&quot;表示回车,&quot;\t&quot;相当于TAB。想在里面输出特殊符号还是要到转义符（&quot; \ &quot;）的。</p>
<p><strong>先知道单引号双引号什么区别吗</strong></p>
<p>理论：在使用单引号时，程序不会首先判断该字符串中是否含有变量，而是将全部内容当成字符串来输出；在使用双引号时，程序首先会去判断字符串中是否含有变量，如果含有变量，则直接输出变量值。</p>
<p>举个栗子：</p>
<pre class="highlight"><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="variable">$b</span>=<span class="string">&#x27;字符串&#x27;</span>;		<span class="comment">//定义一个字符串变量</span></span><br><span class="line">	<span class="keyword">echo</span><span class="string">&quot;<span class="subst">$b</span>&quot;</span>;		<span class="comment">//用双引号输出</span></span><br><span class="line">	<span class="keyword">echo</span><span class="string">&quot;&lt;p&gt;&quot;</span>;		<span class="comment">//输出段标记</span></span><br><span class="line">	<span class="keyword">echo</span><span class="string">&#x27;$b&#x27;</span>;		<span class="comment">//用单引号输出</span></span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre>
<p>结果：</p>
<p><img src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210914131939.png" alt="" / srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210914131939.png" class="lozad post-image"></p>
<p>注意：PHP中单引号字符串定义简单、运行速度相对于双引号字符串快一些，如果没有特殊要求应尽量使用单引号。具体原因请看度娘。</p>
<p>3）定界符形式</p>
<p>这个不多介绍，用的少，鄙人推荐你用度娘看看。</p>
<p><strong>3.整型（nteger）</strong></p>
<p>整数数据类型只能包含整数，可以为正数，也可以为负数。其取值范围为 -2147483648~+2147483647。在给整数变量赋值时，可以采用十进制、十六进制或者八进制形式。要使用八进制，数字前必须加上&quot;0（零）&quot;；要使用十六进制，数字前必须加上&quot;0x&quot;，在表达式计算中都是以十进制数字输出。</p>
<p>上例子：</p>
<pre class="highlight"><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">	<span class="variable">$jl_1</span>=<span class="number">123456</span>;		<span class="comment">//声明十进制整数</span></span><br><span class="line">	<span class="variable">$jl_2</span>=<span class="number">0123456</span>;		<span class="comment">//声明八进制整数</span></span><br><span class="line">	<span class="variable">$jl_3</span>=<span class="number">0x123456</span>;		<span class="comment">//声明十六进制整数</span></span><br><span class="line">	<span class="keyword">echo</span><span class="string">&#x27;数字：123456的不同进制输出结果:&lt;p&gt;&#x27;</span>;</span><br><span class="line">	<span class="keyword">echo</span><span class="string">&quot;十进制：<span class="subst">$jl_1</span> &lt;p&gt;&quot;</span>;</span><br><span class="line">	<span class="keyword">echo</span><span class="string">&quot;八进制：<span class="subst">$jl_2</span> &lt;p&gt;&quot;</span>;</span><br><span class="line">	<span class="keyword">echo</span><span class="string">&quot;十六进制：<span class="subst">$jl_3</span> &lt;p&gt;&quot;</span>;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre>
<p>结果：</p>
<p><img src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210914165422.png" alt="" / srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210914165422.png" class="lozad post-image"></p>
<p>注意：PHP中不支持无符号整数，所以无法像其他语言一样把整数都表示成整数，即最大值翻一倍。最大值可以用常量PHP_INT_MAX来表示，如果一个数或者运算结果超出了整型范围，将返回float。</p>
<p><strong>4.浮点型（float/double）</strong></p>
<p>浮点型也称为浮点数（float），双精度数（double）或实数（real）。浮点型数据类型用于存储整数或小数，是一种近似的数值。它提供了比整数大得多的精度，可以精确到小数点的后十五位。浮点数的字长和平台相关。浮点数既可以表示为简单的浮点数常量，如1.234；也可以表示为科学计数法的形式，位数和指数之间用e或E隔开，如1.2e3，1.2E3。</p>
<p>上例子：</p>
<pre class="highlight"><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="keyword">echo</span> <span class="variable">$a</span>=<span class="number">202.4</span>;		<span class="comment">//以小数形式表达浮点数</span></span><br><span class="line">	<span class="keyword">echo</span> <span class="string">&quot;&lt;br&gt;&quot;</span>;</span><br><span class="line">	<span class="keyword">echo</span> <span class="variable">$b</span>=<span class="number">2.024e8</span>;	<span class="comment">//以科学计数法形式表示浮点数</span></span><br><span class="line">	<span class="keyword">echo</span> <span class="string">&quot;&lt;br&gt;&quot;</span>;</span><br><span class="line">	<span class="keyword">echo</span> <span class="variable">$c</span>=<span class="number">20.24e-8</span>;	<span class="comment">//以科学计数法形式表示浮点数</span></span><br><span class="line">	<span class="keyword">echo</span> <span class="string">&quot;&lt;br&gt;&quot;</span>;</span><br><span class="line"><span class="meta">?&gt;</span></span><br><span class="line">		</span><br></pre>
<p>结果：</p>
<p><img src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210914173056.png" alt="" / srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210914173056.png" class="lozad post-image"></p>
<p>注意：PHP中浮点数的精度计算有点问题，所以在应用浮点数时，尽量不要去比较两个浮点数大小，也不要将浮点数相加减，此时那个很小的数可能被忽略。如果有需要进行高精度的科学计算，可以使用PHP内置函数gmp()函数。</p>
<h3 id="复合数据类型"><a class="markdownIt-Anchor" href="#复合数据类型"></a> 复合数据类型</h3>
<p><strong>1.数组（array）</strong></p>
<p>数组是一系列相关的数据的集合，以某种特定的方式进行排列，形成一个可操作的整体。数组中可以包含：标量数据、数组、对象、资源。</p>
<p>数组中的每一个数据称为一个元素，元素包括索引和值两部分。在PHP中，元素索引只能由数字或字符串组成。元素值可以是基本数据类型，也可以是复合数据类型(如以一个数组作为元素) ；可以是相同的数据类型，也可以是不同的数据类型。PHP中可以使用多种方法构建数组。</p>
<p>上例子：</p>
<pre class="highlight"><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="variable">$num</span>[<span class="number">0</span>]=<span class="string">&quot;red&quot;</span>;</span><br><span class="line"><span class="variable">$num</span>[<span class="number">1</span>]=<span class="string">&quot;green&quot;</span>;</span><br><span class="line"><span class="variable">$num</span>[<span class="number">2</span>]=<span class="string">&quot;blue&quot;</span>;</span><br><span class="line"><span class="variable">$num</span>[<span class="string">&quot;blue&quot;</span>]=<span class="number">6</span>;</span><br><span class="line"><span class="keyword">echo</span> <span class="variable">$num</span>[<span class="number">1</span>];		<span class="comment">// green</span></span><br><span class="line"><span class="keyword">echo</span> <span class="string">&quot;&lt;br&gt; &quot;</span>;</span><br><span class="line"><span class="keyword">echo</span> <span class="variable">$num</span>[<span class="string">&quot;blue&quot;</span>];		<span class="comment">// 6</span></span><br><span class="line"><span class="keyword">echo</span> <span class="string">&quot;&lt;br&gt;&quot;</span>;		</span><br><span class="line"><span class="comment">//使用array()构建数组</span></span><br><span class="line"><span class="variable">$arr</span>=<span class="keyword">array</span>(<span class="string">&quot;red&quot;</span>=&gt;<span class="string">&quot;ccy&quot;</span>,<span class="number">1</span>=&gt;<span class="literal">true</span>);</span><br><span class="line">print_r(<span class="variable">$arr</span>) ;		<span class="comment">//用print_r() 函数查看数组中的全部内容</span></span><br><span class="line"><span class="keyword">echo</span> <span class="string">&quot;&lt;br&gt;&quot;</span>;</span><br><span class="line"><span class="keyword">echo</span> <span class="variable">$arr</span>[<span class="string">&quot;red&quot;</span>];		<span class="comment">//通过下标访问单个元素，ccy</span></span><br><span class="line"><span class="keyword">echo</span> <span class="string">&quot;&lt;br&gt;&quot;</span>;</span><br><span class="line"><span class="keyword">echo</span> <span class="variable">$arr</span>[<span class="number">1</span>];		<span class="comment">//1</span></span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre>
<p>结果：</p>
<p><img src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210915102859.png" alt="" / srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://xwtuku.oss-cn-beijing.aliyuncs.com/img/20210915102859.png" class="lozad post-image"></p>
<p>是不是看完头很大，是的我们还没有接触那么多函数，这只是个简单的例子，后续慢慢学习就会明白了。</p>
<p><strong>2.对象（object）</strong></p>
<p>对象是一种更高级的数据类型，对象类型的变量由一组属性值和一组方法构成。在这里不详细讲述。</p>

  </div>
  <div>
    
      <div 
        class="post-note note-warning copyright" 
        style="margin-top: 42px">
        <p>
          <span style="font-weight: bold;">作者：</span><a 
            target="_blank" 
            rel="nofollow noopener noreferrer" 
            href="/about">
            白开画 and 徐威
          </a>
        </p>
        <p>
          <span style="font-weight: bold;">文章链接：</span><a 
            target="_blank" 
            rel="nofollow noopener noreferrer" 
            href="http://www.baikaihua.gitee.io/2021/09/19/PHP%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/index.html">
            http://www.baikaihua.gitee.io/2021/09/19/PHP%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/index.html
          </a>
        </p>
        <p><span style="font-weight: bold;">版权声明：</span>本博客所有文章除特别声明外，均采用<a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA 4.0 协议</a>。转载请注明出处！</p>
      </div>
    
  </div>
</article>
<div class="nav">
  
    <div class="nav-item-prev">
      <a 
        href="/2021/09/19/PHP%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/index.html" 
        class="nav-link">
        <i class="iconfont icon-left nav-prev-icon"></i>
        <div>
          <div class="nav-label">上一篇</div>
          
            <div class="nav-title">PHP语言基础 </div>
          
        </div>
      </a>
    </div>
  
  
    <div class="nav-item-next">
      <a 
        href="/2021/09/19/01%EF%BC%8C%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%A6%82%E8%BF%B0/index.html" 
        class="nav-link">
        <div>
          <div class="nav-label">下一篇</div>
          
            <div class="nav-title">计算机网络概述 </div>
          
        </div>
        <i class="iconfont icon-right nav-next-icon"></i>
      </a>
    </div>
  
</div>

  <div 
    class="card card-content comment-card" 
    style="margin-top: 16px;">
    <div class="comment-card-title">评论</div>
    
  <div id="vcomments"></div>
  
  <script>
    loadScript("//unpkg.com/valine/dist/Valine.min.js");
    var oldLoadVa = window.onload;
    window.onload = function () {
      oldLoadVa && oldLoadVa();
      new Valine({
        el: '#vcomments',
        appId: 'C2ey5RzCeMGvikIpezIqS1fW-gzGzoHsz',
        appKey: 'yNj1HPpcuT4nFzgDG1hfxiwX',
        placeholder: 'Just go go',
        path: window.location.pathname,
        avatar: 'mp',
        meta: ["nick","mail","link"],
        pageSize: '10',
        lang: '',
        visitor: 'false',
        highlight: true,
        recordIP: false,
        
        
        
        enableQQ: 'false',
        requiredFields: [],
      });
    };
  </script>

  </div>

<div 
  class="card card-content toc-card" 
  id="mobiletoc">
  <div class="toc-header">
  <i 
    class="iconfont icon-menu" 
    style="padding-right: 2px;">
  </i>目录
</div>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#php%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.</span> <span class="toc-text"> PHP数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%87%E9%87%8F%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.1.</span> <span class="toc-text"> 标量数据类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%8D%E5%90%88%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.2.</span> <span class="toc-text"> 复合数据类型</span></a></li></ol></li></ol>
</div></main>
            <aside class="left-column">
              
              <div class="card card-author">
                
  <img 
    src="https://gitee.com/baikaihua/tochang/raw/master/src=http___b-ssl.duitang.com_uploads_item_201607_07_20160707163006_EnLeG.jpeg&refer=http___b-ssl.duitang.jpg" 
    class="author-img" 
    alt="author avatar">

<p class="author-name">白开画 and 徐威</p>
<p class="author-description">欢迎！</p>
<div class="author-message">
  <a 
    class="author-posts-count" 
    href="/archives">
    <span>33</span>
    <span>文章</span>
  </a>
  <a 
    class="author-categories-count" 
    href="/categories">
    <span>11</span>
    <span>分类</span>
  </a>
  <a 
    class="author-tags-count" 
    href="/tags">
    <span>37</span>
    <span>标签</span>
  </a>
</div>

              </div>
               <div class="sticky-tablet">
  
  
    <article class="display-when-two-columns spacer">
      <div class="card card-content toc-card">
        <div class="toc-header">
  <i 
    class="iconfont icon-menu" 
    style="padding-right: 2px;">
  </i>目录
</div>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#php%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.</span> <span class="toc-text"> PHP数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%87%E9%87%8F%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.1.</span> <span class="toc-text"> 标量数据类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%8D%E5%90%88%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.2.</span> <span class="toc-text"> 复合数据类型</span></a></li></ol></li></ol>
      </div>
    </article>
  
  
  <article class="card card-content categories-widget">
    <div class="categories-card">
  <div class="categories-header">
    <i 
      class="iconfont icon-fenlei" 
      style="padding-right: 2px;">
    </i>分类
  </div>
  <div class="categories-list">
    
      <a href="/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/">
        <div class="categories-list-item">
          计算机网络
          <span class="categories-list-item-badge">5</span>
        </div>
      </a>
    
      <a href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">
        <div class="categories-list-item">
          数据库
          <span class="categories-list-item-badge">3</span>
        </div>
      </a>
    
      <a href="/categories/PHP/">
        <div class="categories-list-item">
          PHP
          <span class="categories-list-item-badge">14</span>
        </div>
      </a>
    
      <a href="/categories/Windows%E7%B3%BB%E7%BB%9F/">
        <div class="categories-list-item">
          Windows系统
          <span class="categories-list-item-badge">1</span>
        </div>
      </a>
    
      <a href="/categories/Python/">
        <div class="categories-list-item">
          Python
          <span class="categories-list-item-badge">1</span>
        </div>
      </a>
    
      <a href="/categories/Linux/">
        <div class="categories-list-item">
          Linux
          <span class="categories-list-item-badge">1</span>
        </div>
      </a>
    
      <a href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/">
        <div class="categories-list-item">
          数据结构与算法
          <span class="categories-list-item-badge">2</span>
        </div>
      </a>
    
      <a href="/categories/%E7%BD%91%E7%BB%9C/">
        <div class="categories-list-item">
          网络
          <span class="categories-list-item-badge">1</span>
        </div>
      </a>
    
      <a href="/categories/%E8%B7%AF%E7%94%B1%E4%BA%A4%E6%8D%A2/">
        <div class="categories-list-item">
          路由交换
          <span class="categories-list-item-badge">3</span>
        </div>
      </a>
    
      <a href="/categories/%E8%BD%AC%E8%BD%BD/">
        <div class="categories-list-item">
          转载
          <span class="categories-list-item-badge">1</span>
        </div>
      </a>
    
      <a href="/categories/python/">
        <div class="categories-list-item">
          python
          <span class="categories-list-item-badge">1</span>
        </div>
      </a>
    
  </div>
</div>
  </article>
  
  <article class="card card-content tags-widget">
    <div class="tags-card">
  <div class="tags-header">
    <i 
      class="iconfont icon-biaoqian" 
      style="padding-right: 2px;">
    </i>热门标签
  </div>
  <div class="tags-list">
    
      <a 
        href="/tags/%E7%99%BD%E5%BC%80%E7%94%BB/" 
        title="白开画">
        <div class="tags-list-item">白开画</div>
      </a>
    
      <a 
        href="/tags/%E5%BE%90%E5%A8%81/" 
        title="徐威">
        <div class="tags-list-item">徐威</div>
      </a>
    
      <a 
        href="/tags/PHP/" 
        title="PHP">
        <div class="tags-list-item">PHP</div>
      </a>
    
      <a 
        href="/tags/web%E8%84%9A%E6%9C%AC/" 
        title="web脚本">
        <div class="tags-list-item">web脚本</div>
      </a>
    
      <a 
        href="/tags/%E7%BD%91%E7%BB%9C/" 
        title="网络">
        <div class="tags-list-item">网络</div>
      </a>
    
      <a 
        href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/" 
        title="计算机网络">
        <div class="tags-list-item">计算机网络</div>
      </a>
    
      <a 
        href="/tags/%E5%8D%8E%E4%B8%BA/" 
        title="华为">
        <div class="tags-list-item">华为</div>
      </a>
    
      <a 
        href="/tags/%E5%8D%8E%E4%B8%BA%E8%AE%A4%E8%AF%81/" 
        title="华为认证">
        <div class="tags-list-item">华为认证</div>
      </a>
    
      <a 
        href="/tags/%E8%B7%AF%E7%94%B1%E4%BA%A4%E6%8D%A2/" 
        title="路由交换">
        <div class="tags-list-item">路由交换</div>
      </a>
    
      <a 
        href="/tags/GVRP/" 
        title="GVRP">
        <div class="tags-list-item">GVRP</div>
      </a>
    
      <a 
        href="/tags/VLAN/" 
        title="VLAN">
        <div class="tags-list-item">VLAN</div>
      </a>
    
      <a 
        href="/tags/%E5%9F%BA%E7%A1%80/" 
        title="基础">
        <div class="tags-list-item">基础</div>
      </a>
    
      <a 
        href="/tags/ip/" 
        title="ip">
        <div class="tags-list-item">ip</div>
      </a>
    
      <a 
        href="/tags/%E5%A4%A7%E6%95%B0/" 
        title="大数">
        <div class="tags-list-item">大数</div>
      </a>
    
      <a 
        href="/tags/python/" 
        title="python">
        <div class="tags-list-item">python</div>
      </a>
    
      <a 
        href="/tags/%E5%91%BD%E4%BB%A4%E6%8F%90%E7%A4%BA%E7%AC%A6/" 
        title="命令提示符">
        <div class="tags-list-item">命令提示符</div>
      </a>
    
  </div>
</div>
  </article>
  
  
</div>
            </aside>
            <aside class="right-column">
              <div class="sticky-widescreen">
  
  
    <article class="card card-content toc-card">
      <div class="toc-header">
  <i 
    class="iconfont icon-menu" 
    style="padding-right: 2px;">
  </i>目录
</div>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#php%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.</span> <span class="toc-text"> PHP数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%87%E9%87%8F%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.1.</span> <span class="toc-text"> 标量数据类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%8D%E5%90%88%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.2.</span> <span class="toc-text"> 复合数据类型</span></a></li></ol></li></ol>
    </article>
  
  
  <article class="card card-content">
    <div class="recent-posts-card">
  <div class="recent-posts-header">
    <i 
      class="iconfont icon-wenzhang_huaban" 
      style="padding-right: 2px;">
    </i>最近文章
  </div>
  <div class="recent-posts-list">
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-12-13</div>
        <a href="/2021/12/13/python%E7%88%AC%E5%8F%96%E6%B7%98%E5%AE%9D%E5%95%86%E5%93%81/index.html"><div class="recent-posts-item-content">python爬取淘宝商品</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-12-13</div>
        <a href="/2021/12/13/PHP%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/index.html"><div class="recent-posts-item-content">PHP字符串常用操作</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-11-29</div>
        <a href="/2021/11/29/PHP%E8%AE%A4%E8%AF%86%E5%AD%97%E7%AC%A6%E4%B8%B2/index.html"><div class="recent-posts-item-content">PHP认识字符串</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-11-21</div>
        <a href="/2021/11/21/PHP%E5%87%BD%E6%95%B0%E7%9A%84%E5%BA%94%E7%94%A8/index.html"><div class="recent-posts-item-content">PHP函数的应用</div></a>
      </div>
    
  </div>
</div>
  </article>
  
  
</div>
            </aside>
          </div>
        </div>
      </div>
    </div>
     
    <footer class="footer">
  <div class="footer-container">
    <div>
      <div class="footer-dsc">
        <span>
          Copyright ©
          
            2021 -
          
          2021
        </span>
        &nbsp;
        <a 
          href="/" 
          class="footer-link">
          程序小站
        </a>
      </div>
    </div>

    
      <div class="footer-dsc">
        
          Powered by
          <a 
            href="https://hexo.io/" 
            class="footer-link" 
            target="_blank" 
            rel="nofollow noopener noreferrer">
            &nbsp;Hexo
          </a>
        
        
          <span>&nbsp;|&nbsp;</span>
        
        
          Theme -
          <a 
            href="https://github.com/theme-kaze" 
            class="footer-link" 
            target="_blank"
            rel="nofollow noopener noreferrer">
            &nbsp;Kaze
          </a>
        
      </div>
    
    
    
    
      <div class="footer-dsc">
        
          本站总访问量<span id="busuanzi_value_site_pv"></span>次
        
        
          <span>&nbsp;|&nbsp;</span>
        
        
          本站总访客数<span id="busuanzi_value_site_uv"></span>次
        
      </div>
      
    
</footer> 
    
  <a 
    role="button" 
    id="scrollbutton" 
    class="basebutton" 
    aria-label="回到顶部">
    <i class="iconfont icon-arrowleft button-icon"></i>
  </a>

<a 
  role="button" 
  id="menubutton" 
  class="basebutton">
  <i class="iconfont icon-menu button-icon"></i>
</a>
<a 
  role="button" 
  id="popbutton" 
  class="basebutton" 
  aria-label="控制中心">
  <i class="iconfont icon-expand button-icon"></i>
</a>
<a 
  role="button" 
  id="darkbutton" 
  class="basebutton darkwidget" 
  aria-label="夜色模式">
  <i class="iconfont icon-weather button-icon"></i>
</a>
<a 
  role="button" 
  id="searchbutton" 
  class="basebutton searchwidget" 
  aria-label="搜索">
  <i class="iconfont icon-search button-icon"></i>
</a> 
     
     
      

  
  
    
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css">

  
 
     
     
      <script>
  var addImgLayout = function () {
    var img = document.querySelectorAll('.post-content img')
    var i
    for (i = 0; i < img.length; i++) {
      var wrapper = document.createElement('a')
      wrapper.setAttribute('href', img[i].getAttribute('data-src'))
      wrapper.setAttribute('aria-label', 'illustration')
      wrapper.style.cssText =
        'width: 100%; display: flex; justify-content: center;'
      if (img[i].alt) wrapper.dataset.caption = img[i].alt
      wrapper.dataset.nolink = true
      img[i].before(wrapper)
      wrapper.append(img[i])
      var divWrap = document.createElement('div')
      divWrap.classList.add('gallery')
      wrapper.before(divWrap)
      divWrap.append(wrapper)
    }
    baguetteBox.run('.gallery')
  }
</script>
<script>
  loadScript(
    "/js/lib/lightbox/baguetteBox.min.js",
    addImgLayout
  )
</script>
 
     
     
    <script src="/js/main.js"></script> 
    
      <script> 
        loadScript('/js/lib/busuanzi.min.js') 
      </script>
     
    
      <script>
        var addLazyload = function () {
          var observer = lozad('.lozad', {
            load: function (el) {
              el.srcset = el.getAttribute('data-src')
            },
            loaded: function (el) {
              el.classList.add('loaded')
            },
          })
          observer.observe()
        }
      </script>
      <script>
        loadScript('/js/lib/lozad.min.js', addLazyload)
      </script>
     
    
    
      <script>
        setTimeout(() => {localSearch("search.json")}, 0)
      </script>
    
  </body>
</html>
